package org.peterf.foxish.engine.input;

import org.peterf.foxish.engine.Engine;
import org.peterf.foxish.surface.SurfaceView;

import android.app.Activity;
import android.content.pm.PackageManager;
import android.util.Log;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnKeyListener;
import android.view.View.OnTouchListener;

public class InputEngine implements OnTouchListener, OnKeyListener {

    private Engine engine;

    private FingerEvent eventWrapper;

    private boolean hasMultiTouch;

    public InputEngine(Engine engine) {
        this.engine = engine;
        eventWrapper = new FingerEvent(engine);
        hasMultiTouch = engine
                .getContext()
                .getPackageManager()
                .hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH);
    }

    public void attachSurface(SurfaceView surface) {
        surface.setOnTouchListener(this);
        surface.setOnKeyListener(this);
    }

    public boolean hasMultiTouch() {
        return hasMultiTouch;
    }

    public boolean onTouch(View v, MotionEvent event) {
        eventWrapper.wrap(event);
        return engine.onTouch(eventWrapper);
    }

    public boolean onKey(View v, int keyCode, KeyEvent event) {
        return engine.onKey(v, keyCode, event);
    }


}
